package com.qqb.init;

import com.qqb.pojo.Edu;
import com.qqb.pojo.Job;
import com.qqb.pojo.PaperType;
import com.qqb.service.EduService;
import com.qqb.service.JobService;
import com.qqb.service.PaperTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 初始化缓存
 */
@Component
public class Init implements CommandLineRunner {


    @Autowired
    private RedisTemplate redisTemplate;

    @Resource
    private PaperTypeService paperTypeService;

    @Resource
    private EduService eduService;

    @Resource
    private JobService jobService;

    /**
     * 项目启动，自动加载到redis中
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        List<PaperType> paperTypeList = paperTypeService.findAll();
        List<Edu> eduList = eduService.findAll();
        List<Job> jobList = jobService.findAll();

        redisTemplate.boundValueOps("PaperType").set(paperTypeList);
        redisTemplate.boundValueOps("Edu").set(eduList);
        redisTemplate.boundValueOps("Job").set(jobList);
    }
}
